package com.houxiurong.controller;

import com.houxiurong.entity.User;
import com.houxiurong.service.UserService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Created by houxiurong on 2017/6/29.
 */
@Controller
public class IndexController {

    @Value("${userString}")
    private String userString;//userString

    @Autowired
    private UserService userService;

    @RequestMapping("/index")
    public String showIndex(Model model){
        model.addAttribute("userString",userString);
        return "index";
    }

    @RequestMapping(value = "getUserByName/{name}",method = {RequestMethod.GET})
    public String getUserByName(@PathVariable("name") String name, Model model) {
        User user=userService.findUserByName(name);
        model.addAttribute("user",user);
        return "user";
    }

    @RequestMapping(value = "listUser",method = {RequestMethod.GET})
    public String listUser(Model model) {
        String name="houxiurong1";
        User user=userService.findUserByName(name);
        model.addAttribute("user",user);

        List<User> users=userService.findAll();
        model.addAttribute("users",users);
        return "user";
    }


}
